﻿package common;

import java.util.ArrayList;

/**
 *	用于切割construct传送过来的字符串
 * Created by Administrator on 2016/12/23.
 */
public class Split {
    public ArrayList<String> splitList(String str){
        ArrayList<String> list=new ArrayList<String>();
        ArrayList<Integer> timeList=new ArrayList<Integer>();
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)==','){
                timeList.add(i);
            }
        }
        int index=0;
        for(int i=0;i<=timeList.size();i++){
            if(i!=timeList.size()){
                list.add(str.substring(index,timeList.get(i)));
                index=timeList.get(i)+1;
            } else {
                list.add(str.substring(index,str.length()));
            }
        }
        return list;
    }
    //用于分割特殊字符串，有带单引号的
    public ArrayList<String> splitSaveMessage(String str){
    	//第一个单引号和最后一个单引号的位置
    	int firstIndex = str.indexOf("'");
    	int lastIndex = str.lastIndexOf("'");
    	String temp = str.substring(firstIndex + 1, lastIndex);
    	ArrayList<String> list = new ArrayList<>();
    	ArrayList<String> temp1 = splitList(str.substring(0, firstIndex));
    	System.out.println("第一段"+ temp1);
    	for(int i = 0 ; i < temp1.size() - 1	;i++){
    		list.add(temp1.get(i));
    	}
    	list.add(temp);
    	System.out.println("擁有房產" + temp);
    	temp1 = splitList(str.substring(lastIndex + 2,str.length()));
    	for(int i = 0;i < temp1.size();i++){
    		list.add(temp1.get(i));
    	}
    	System.out.println("第二段"+ temp1);
    	System.out.println("結果集" + list.get(49));
		return list;
    	
    }
}
